/** 返回数组中满足函数的第一个元素的值 */
const arr = [1, 2, 3];
console.log(
  arr.find(
    function (item) {
      return item > this.num;
    },
    { num: 2 }
  )
);

function myFind(fn, thisArg) {
  for (let i = 0; i < this.length; i++) {
    if (fn.call(thisArg, this[i], i, this)) {
      return this[i];
    }
  }
}

Array.prototype.myFind = myFind;

console.log(
  arr.myFind(
    function (item) {
      return item > this.num;
    },
    { num: 2 }
  )
);
